package com.googlecode.jnarwhal.world;

/**
 * Just a Chunk
 * @author Pivo
 *
 */
public class Chunk {
	
	private static final int LENGTHX = 64;
	private static final int LENGTHY = 128;
	private static final int LENGTHZ = 64;
	private Block[] blocks;
	private int posX,posZ;
	
	
	public Chunk (int posX, int posZ){
		this.posX = posX;
		this.posZ = posZ;
		blocks = new Block[LENGTHX*LENGTHY*LENGTHZ];
	}
	
	/**
	 * Generates a new chunk an all Blocks in it... might be moved to an external worldgenerater
	 * @param seed
	 */
	public void generateChunk(int seed){
		
		for(int i =0 ; i < LENGTHX;i++){
			for(int j = 0 ; j < LENGTHZ;j++){
				for(int k =  0 ; k < LENGTHY; k++){
					if(k<=LENGTHY/2){
						blocks[i+LENGTHX*(j+LENGTHZ*k)] = new Dirt(i,k,j);
					}
					else {
						blocks[i+LENGTHX*(j+LENGTHZ*k)] = new Air(i,k,j);
					}
				}
			}
		}
	}
	
	
	
	/**
	 * 
	 * @param x
	 * @param y
	 * @param z
	 * @return Block at (x,y,z)
	 */
	public Block getBlockAt(int x, int y , int z){
		Block block = blocks[x + LENGTHX*(z+LENGTHZ*y)]; 
				
				return block;
	}
	
	/**
	 * Replaces Block at coordinate by air
	 * @param x
	 * @param y
	 * @param z
	 */
	public void destroyBlockAt(int x, int y, int z){
		blocks[x + LENGTHX*(z+LENGTHZ*y)] = new Air(x,y,z);
	}
	
	/**
	 * @return x coordinate of Chunk in World
	 */
	public int getX (){
		return this.posX;
	}
	
	
	/**
	 * @return z coordinate of Chunk in World
	 */
	public int getZ(){
		return this.posZ;
	}
	
}
